﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.DataObjects;
using NUnit.Framework;
using Rhino.Mocks;

using Chefbook.UserActions;
using Chefbook.ViewModels;

namespace UnitTests.UserActionsTests
{
    [TestFixture]
    public class MoveCategoryActionFixture
    {
        private MockRepository mocks;
        private IUserAction action;
        private CategoryViewModel categoryVM, oldParentVM, newParentVM;


        [SetUp]
        public void Init()
        {
            mocks = new MockRepository();
            

            oldParentVM = new CategoryViewModel(new Category(null)) { Name = "OldParent" };
            newParentVM = new CategoryViewModel(new Category(oldParentVM.CategoryModel)) { Name = "NewParent" };
            categoryVM = new CategoryViewModel(new Category(oldParentVM.CategoryModel)) { Name = "MyCategory" };
            Assert.AreEqual(2, oldParentVM.Subcategories.Count);
            Assert.Contains(categoryVM, oldParentVM.Subcategories);
            Assert.AreEqual(0, newParentVM.Subcategories.Count);

            action = new MoveCategoryAction(categoryVM,newParentVM) ;
        }

        [Test]
        public void DoActionTest()
        {
            action.DoAction();
            Assert.AreEqual(1, oldParentVM.Subcategories.Count);
            Assert.Contains(categoryVM, newParentVM.Subcategories);
            Assert.False(oldParentVM.Subcategories.Contains(categoryVM));
            Assert.AreEqual(1, newParentVM.Subcategories.Count);
        }

        [Test]
        public void UndoActionTest()
        {
            action.DoAction();
            action.UndoAction();
            Assert.AreEqual(2, oldParentVM.Subcategories.Count);
            Assert.Contains(categoryVM, oldParentVM.Subcategories);
            Assert.AreEqual(0, newParentVM.Subcategories.Count);
        }

        [Test]
        public void UndoActionWithoutDoingTest()
        {
            UserActionTestsHelper.UndoActionWithoutDoingTest(action);
        }

        [Test]
        public void UndoActionTwiceAfterDoingTest()
        {
            UserActionTestsHelper.UndoActionTwiceAfterDoingTest(action);
        }

        [Test]
        public void DoActionTwiceTest()
        {
            UserActionTestsHelper.DoActionTwiceTest(action);
        }

        [Test]
        public void ActionNameTest()
        {
            Assert.AreEqual(string.Format("Move Category '{0}' from '{1}' to '{2}'", categoryVM, oldParentVM, newParentVM), action.ToString());
        }
    }
}
